@layout("/common/_container.html"){
<div class="layui-card">
	<div class="layui-form layui-card-header layuiadmin-card-header-auto" id="form1">

		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">支付状态</label>
				<div class="layui-input-inline">
					<select name="payState" id="payState">
						<option value="">全部</option>
						<option value="1">待支付</option>
						<option value="2">已支付</option>
					</select>
				</div>
			</div>
			<div class="layui-inline">
				<label class="layui-form-label">支付方式</label>
				<div class="layui-input-inline">
					<select name="payType" id="payType">
						<option value="">全部</option>
						<option value="1">支付宝</option>
						<option value="2">微信</option>
						<option value="2">银行转账</option>
					</select>
				</div>
			</div>
			<div class="layui-inline">
				<div class="layui-inline">
					<label class="layui-form-label">创建时间</label>
					<div class="layui-input-inline">
						<input type="text" class="layui-input" id="startDate" name="startDate" autocomplete="off"
							   placeholder="开始时间">
					</div>
					<div class="layui-form-mid">-</div>
					<div class="layui-input-inline">
						<input type="text" class="layui-input" id="endDate" name="endDate" autocomplete="off"
							   placeholder="结束时间">
					</div>
				</div>
			</div>
		</div>
		<div class="layui-form-item">
			<div class="layui-inline">
				<label class="layui-form-label">订单号</label>
				<div class="layui-input-block" style="width: 190px;">
					<input type="text" name="orderId" id="orderId" placeholder="订单号" autocomplete="off"
						   class="layui-input">
				</div>
			</div>
			<div class="layui-inline" style="margin-left: 10px;">
				<label class="layui-form-label">用户名</label>
				<div class="layui-input-block" style="width: 190px;">
					<input type="text" name="userName" id="userName" placeholder="用户名" autocomplete="off"
						   class="layui-input">
				</div>
			</div>
			<div class="layui-inline" style="margin-left: 10px;">
				<label class="layui-form-label">汇款凭证号</label>
				<div class="layui-input-block" style="width: 190px;">
					<input type="text" name="swiftNo" id="swiftNo" placeholder="汇款凭证号" autocomplete="off"
						   class="layui-input">
				</div>
			</div>
			<div class="layui-inline" style="margin-left: 10px;">
				<label class="layui-form-label"></label>
				<button class="layui-btn layuiadmin-btn-useradmin" data-type="reload"><i class="layui-icon layui-icon-search layuiadmin-button-btn"></i></button>
			</div>
			<div class="layui-inline"  style="float:right;">
				<label class="layui-form-label"></label>
				@if(shiro.hasPermission("/order/export")){
				<button class="layui-btn layui-btn-normal layui-btn-radius" id="export" lay-filter="export" lay-submit>
					&nbsp;导&nbsp;&nbsp;出&nbsp;
				</button>
				@}
			</div>
		</div>

	</div>
  <div class="layui-card-body">

  <table class="layui-hidden" id="table" lay-filter="table"></table>
  	<script type="text/html" id="oper">
		  	@if(shiro.hasPermission("/order/update")){
			{{#  if(d.payType==3 &&d.payState == 1){ }}
  				<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit" title="修改">&nbsp;修&nbsp;&nbsp;改&nbsp;</a>
				<a class="layui-btn layui-btn-xs" lay-event="delOrder" title="取消">&nbsp;取&nbsp;&nbsp;消&nbsp;</a>
			{{#  } }}
			@}
			@if(shiro.hasPermission("/order/detail")){
			<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="detail" title="详情">&nbsp;详&nbsp;&nbsp;情&nbsp;</a>
			@}
	</script>
  </div>
</div>

<script>
layui.config({
	base: Feng.ctxPath + "/static/layuiadmin/" //静态资源所在路径
}).extend({
	index: 'lib/index' //主入口模块
}).use(['index', 'layer','table', 'form','laydate'],function(){
	
	var $ = layui.$
  	,form = layui.form
  	,table = layui.table
	,laydate = layui.laydate;

    form.on('submit(export)', function (data) {
        var field = data.field; //获取提交的字段
        //墨绿深蓝风
        layer.alert('正在导出. . .完成后请手动关闭弹窗', {
            skin: 'layui-layer-lan'
            ,closeBtn: 0
            //,anim: 4 //动画类型
        });

        //模拟form表单提交导出
        postExcelFile(field, Feng.ctxPath + "/order/export");
    });

    //开始日期
    var insStart = laydate.render({
        elem: '#startDate'
        ,type: 'datetime'
        ,done: function(value, date){
            //更新结束日期的最小日期
            insEnd.config.min = lay.extend({}, date, {
                month: date.month - 1
            });
            //自动弹出结束日期的选择器
            insEnd.config.elem[0].focus();
        }
    });
    var insEnd = laydate.render({
        elem: '#endDate'
        ,type: 'datetime'
        ,done: function(value, date){
            //更新开始日期的最大日期
            insStart.config.max = lay.extend({}, date, {
                month: date.month - 1
            });
        }
    });

	var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
	table.render({
	    elem: '#table'
	    ,url: Feng.ctxPath + '/order/list'
	    ,cellMinWidth: 60
	    // ,height: 'full-168' //设置高度
	    ,height: '' //设置高度
	    ,cols: [[
	        {title: '序号', type: 'numbers'},
	        {title: '订单号', field: 'orderId', width:230},
	        {title: '用户名', field: 'userName'},
            {title: '创建时间', field: 'createTime',width:170},
            {title: '支付方式', field: 'payType',templet:function (d) {
                    return d.payType === 1 ? "支付宝" : (d.payType === 2 ? "微信" : (d.payType === 3 ? "银行转账" : "未选择支付方式"));
                }},
            {title: '汇款凭证号', field: 'swiftNo'},
            {title: '支付状态', field: 'payState',templet:function (d) {
                    return d.payState === 1 ? "待支付" : (d.payState === 2 ? "已支付" : "");
                }},
            {title: '订单金额', field: 'orderPrice',templet: function (d) {
                    return d.orderPrice != null && d.orderPrice != '' ?(parseFloat(d.orderPrice).toFixed(2)) : "";
                }},
	        {title: '操作',fixed: 'right', width:200, align:'center',fixed: 'right', toolbar: '#oper'}
	    ]]
	    ,page:true
	    ,loading:true
	    ,text: {
	        none: '暂无相关数据' 
	      }
	    ,done: function(res){
	    	layer.close(loadingIndex);
        }
	});
	
	//事件
	var active = {
		//加载
	   	reload: function(){
	       var payState = $('#payState').val();
	       var payType = $('#payType').val();
	       var startDate = $('#startDate').val();
	       var endDate = $('#endDate').val();
	       var orderId = $('#orderId').val();
	       var userName = $('#userName').val();
	       var swiftNo = $('#swiftNo').val();

	       var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
	       //执行表格重载
	       table.reload('table', {
	    	 height: 'full-168' //设置高度
	    	 ,where: {
                   payState: payState,
                   payType: payType,
                   startDate: startDate,
                   endDate: endDate,
                   orderId: orderId,
                   userName: userName,
                   swiftNo: swiftNo
	         }
	       ,page:true
	       ,done: function(res){
		    	layer.close(loadingIndex);
	        }
	      });
	    },

     	add: function(){
     	 var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
         layer.open({
           type: 2
           ,title: '添加订单表'
           ,content: Feng.ctxPath + '/order/order_add'
           ,maxmin: true
           ,area: ['720px', '445px']
           ,btn: ['确定', '取消']
           ,yes: function(index, layero){
             var iframeWindow = window['layui-layer-iframe'+ index]
             ,submitID = 'order-submit'
             ,submit = layero.find('iframe').contents().find('#'+ submitID);
             //监听提交
             iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                 var loading2 = layer.load(2);
               var field = data.field; //获取提交的字段
               var ajax = new $ax(Feng.ctxPath + "/order/add", function (data) {
                   Feng.success("添加成功!");
                   table.reload('table',{
                	  done: function(res){
           		    	layer.close(loadingIndex);
           	          }
                   }); //数据刷新
                   layer.close(loading2); //关闭弹层
                   layer.close(index); //关闭弹层
               }, function (data) {
                   Feng.error("添加失败!" + data.responseJSON.message + "!");
               },true);
               ajax.setData(field);
               ajax.start();
             });  
             submit.trigger('click');
           }
           ,btn2: function(index, layero){
      	   		layer.close(loadingIndex);
           }
           ,cancel:function(index, layero){
      	   	layer.close(loadingIndex);
           }
         }); 
       }
   };
  
   
   $('.layui-btn.layuiadmin-btn-useradmin').on('click', function(){
     var type = $(this).data('type');
     active[type] ? active[type].call(this) : '';
   });
	

 //监听工具条
   table.on('tool(table)', function(obj){
     var data = obj.data;
     if(obj.event === 'detail'){
         var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
    	 window.location.href = Feng.ctxPath + "/order/detail/"+data.orderId;
     }else if(obj.event === 'edit'){
         layer.confirm('确定修改支付状态为已支付？', function(index){
             var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 ,shade: 0.01});
             var ajax = new $ax(Feng.ctxPath + "/order/update", function (data) {
                 Feng.success("修改成功!");
                 table.reload('table',{
                     done: function(res){
                         layer.close(loadingIndex);
                     }
                 }); //数据刷新
                 layer.close(index); //关闭弹层
             }, function (data) {
                 Feng.error("修改失败!" + data.responseJSON.message + "!");
             },true);
             ajax.set("orderId", data.orderId);
             ajax.start();
         });

       // var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 });
       // layer.open({
       //   type: 2
       //   ,title: '订单表用户'
       //   ,content: Feng.ctxPath + '/order/order_update/'+data.id
       //   ,area: ['720px', '390px']
       //   ,btn: ['确定', '取消']
       //   ,yes: function(index, layero){
       //     var iframeWindow = window['layui-layer-iframe'+ index]
       //     ,submitID = 'order-submit'
       //     ,submit = layero.find('iframe').contents().find('#'+ submitID);
       //
       //     //监听提交
       //     iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
       //       var field = data.field; //获取提交的字段
       //       var ajax = new $ax(Feng.ctxPath + "/order/update", function (data) {
       //           Feng.success("修改成功!");
       //           table.reload('table',{
       //         	  done: function(res){
       //    		    	layer.close(loadingIndex);
       //    	          }
       //            }); //数据刷新
       //           layer.close(index); //关闭弹层
       //       }, function (data) {
       //           Feng.error("修改失败!" + data.responseJSON.message + "!");
       //       });
       //       ajax.setData(field);
       //       ajax.start();
       //
       //     });
       //
       //     submit.trigger('click');
       //   }
       //   ,btn2: function(index, layero){
    	//    layer.close(loadingIndex);
       //   }
       //   ,cancel:function(index, layero){
    	//    layer.close(loadingIndex);
       //   }
       // });
     }else if(obj.event === 'delOrder'){
         layer.confirm('确定要取消此订单吗？', function(index){
             var loadingIndex = layer.msg('数据加载中', {icon: 16, time: 0 ,shade: 0.01});
             var ajax = new $ax(Feng.ctxPath + "/order/delete", function (data) {
                 Feng.success("取消成功!");
                 table.reload('table',{
                     done: function(res){
                         layer.close(loadingIndex);
                     }
                 }); //数据刷新
                 layer.close(index); //关闭弹层
             }, function (data) {
                 Feng.error("取消失败!" + data.responseJSON.message + "!");
             },true);
             ajax.set("orderId", data.orderId);
             ajax.start();
         });
     }
   });

    //模拟form表单提交导出
    function postExcelFile(params, url) { //params是post请求需要的参数，url是请求url地址
        var form = document.createElement("form");
        form.style.display = 'none';
        form.action = url;
        form.method = "post";
        document.body.appendChild(form);

        for(var key in params){
            var input = document.createElement("input");
            input.type = "hidden";
            input.name = key;
            input.value = params[key];
            form.appendChild(input);
        }

        form.submit();
        form.remove();
    }
});



   
</script>
@}
